package com.irun.pm.ui;

import com.irun.pm.R;
import com.irun.pm.controller.DriverInfoControllers;
import com.irun.pm.mode.DriverInfo;
import com.irun.pm.utils.StringUtil;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class FugitivesDetailsActivity extends BaseActivity implements OnClickListener{
	private DriverInfoControllers controllers;
	private DriverInfo driverInfo;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fugitives_details);
		controllers = new DriverInfoControllers(this);
		int id = getIntent().getIntExtra("id", 0);
		driverInfo = controllers.queryDriverInfoById(id);
		if(driverInfo!=null){
			((TextView)findViewById(R.id.tvName)).setText(StringUtil.getValue(driverInfo.getName()));
			((TextView)findViewById(R.id.tvSex)).setText(StringUtil.getValue(driverInfo.getSex()));
			((TextView)findViewById(R.id.tvAddress)).setText(StringUtil.getValue(driverInfo.getAddress()));
			((TextView)findViewById(R.id.tvCard)).setText(StringUtil.getValue(driverInfo.getCard()));
			((TextView)findViewById(R.id.tvNativeAddress)).setText(StringUtil.getValue(driverInfo.getNativeAddress()));
			((TextView)findViewById(R.id.tvCar_Number)).setText(StringUtil.getValue(driverInfo.getCardNumber()));
			((TextView)findViewById(R.id.tvNotes)).setText(StringUtil.getValue(driverInfo.getNote()));
			if(!StringUtil.isEmpty(driverInfo.photoPath)){
				Bitmap bmp = BitmapFactory
						.decodeFile(driverInfo.photoPath);
				if(bmp == null)
					bmp = BitmapFactory.decodeResource(getResources(), R.drawable.default_photo);
				((ImageView)findViewById(R.id.ivFugitivesPhoto)).setImageBitmap(bmp);
			}
			findViewById(R.id.ivFugitivesPhoto).setOnClickListener(this);
		}
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.ivPopilationPhoto:
			if(driverInfo!=null && !StringUtil.isEmpty(driverInfo.photoPath)){
				Intent intent = new Intent(this,PhotoView.class);
				intent.putExtra("path", driverInfo.photoPath);
				startActivity(intent);
			}else{
				Toast.makeText(getBaseContext(), "该记录未上传图片", Toast.LENGTH_SHORT).show();
			}
			break;

		default:
			break;
		}
	}
}
